package org.alanlau.job;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * @author alan
 * @version 1.0
 * @date 2020/11/8 16:14
 */
public class Main {
    public static void main(String[] args) throws SchedulerException {
        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = schedulerFactory.getScheduler();

        JobDetail job = JobBuilder.newJob(HelloJob.class)
                .withIdentity("myJob", "group1")
                .usingJobData("jobSays", "hello world")
                .usingJobData("myFloatValue", 3.14f)
                .build();

        SimpleTrigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("myTrigger", "group1")
                .startNow()
                .withSchedule(SimpleScheduleBuilder
                        .simpleSchedule()
                        .withIntervalInSeconds(10)
                        .repeatForever())
                .build();

        // Tell quartz to schedule the job using our trigger
        scheduler.scheduleJob(job, trigger);

        scheduler.start();
    }
}
